<?php
	/* Functions in this file */
	/**************************/

	// GetKeySignature()
	// GetMFCClassName()
	// GetMFCClassSchema()
	// GetPosition()
	// GetRehearsalSign()
	// GetRepeatCount()
	// GetTimeSignature()
	// GetType()
	// IsBar()
	// IsDoubleBar()
	// IsDoubleBarFine()
	// IsFreeTimeBar()
	// IsRepeatEnd()
	// IsRepeatStart()
	// IsValidPosition($position)
	// IsValidRepeatCount($repeatCount)
	// IsValidType($type)
	// SetKeySignature(&$keySignature)
	// SetPosition($position)
	// SetRehearsalSign(&$rehearsalSign)
	// SetRepeatCount($repeatCount)
	// SetTimeSignature(&$timeSignature)
	// SetType($type)
?>
<?php
	 
	 
	class Barline {
		 
		// Default Constants
		const DEFAULT_POSITION = 0;
		const DEFAULT_DATA = 0x00000000;
		 
		// Repeat Count Constants
		const MIN_REPEAT_COUNT = 2;
		const MAX_REPEAT_COUNT = 24;
		 
		 
		const bar = 0;
		const doubleBar = 1;
		const freeTimeBar = 2;
		const repeatStart = 3;
		const openBar = 3;
		const repeatEnd = 4;
		const doubleBarFine = 5;
		 
		 
		 
		const typeMask = 0x000000e0;
		const repeatCountMask = 0x0000001f;
		 
		 
		 
		protected $m_position = self::DEFAULT_POSITION;
		protected $m_data = self::DEFAULT_DATA;
		 
		protected $m_keySignature;
		protected $m_timeSignature;
		protected $m_rehearsalSign;
		 
		 
		// MFC Class Functions
		 
		 
		function GetMFCClassName() {
			return "CMusicBar";
		}
		 
		 
		function GetMFCClassSchema() {
			return 1;
		}
		 
		// Position Functions
		 
		 
		 
		function IsValidPosition($position) {
			return (($position >= 0) && ($position <= 255));
		}
		 
		 
		 
		function SetPosition($position) {
			if (!$this->IsValidPosition($position)) return 0;
			$this->m_position = $position;
			 return 1;
		}
		 
		 
		function GetPosition() {
			return ($this->m_position);
		}
		 
		 
		// Type Functions
		 
		 
		 
		function IsValidType($type) {
			return ($type <= self::doubleBarFine);
		}
		 
		 
		function GetType() {
			return ((($this->m_data & self::typeMask) >> 5));
		}
		 
		 
		function IsBar() {
			return ($this->GetType() == self::bar);
		}
		 
		 
		function IsDoubleBar() {
			return ($this->GetType() == self::doubleBar);
		}
		 
		 
		function IsFreeTimeBar() {
			return ($this->GetType() == self::freeTimeBar);
		}
		 
		 
		function IsRepeatStart() {
			return ($this->GetType() == self::repeatStart);
		}
		 
		 
		function IsRepeatEnd() {
			return ($this->GetType() == self::repeatEnd);
		}
		 
		 
		function IsDoubleBarFine() {
			return ($this->GetType() == self::doubleBarFine);
		}
		 
		// Repeat Count Functions
		 
		 
		 
		function IsValidRepeatCount($repeatCount) {
			return ((($repeatCount >= self::MIN_REPEAT_COUNT) && ($repeatCount <= self::MAX_REPEAT_COUNT)) || ($repeatCount == 0));
		}
		 
		function GetRepeatCount() {
			return (($this->m_data & self::repeatCountMask));
		}
		 
		// Key Signature Functions
		 
		function SetKeySignature(&$keySignature) {
			$this->m_keySignature = $keySignature;
		}
		 
		 
		function GetKeySignature() {
			return ($this->m_keySignature);
		}
		 
		 
		function & GetKeySignatureRef() {
			return ($this->m_keySignature);
		}
		 
		 
		static function & GetKeySignatureConstRef() {
			return ($this->m_keySignature);
		}
		 
		 
		 
		 
		// Time Signature Functions
		 
		function SetTimeSignature(&$timeSignature) {
			$this->m_timeSignature = $timeSignature;
		}
		 
		 
		function GetTimeSignature() {
			return ($this->m_timeSignature);
		}
		 
		 
		function & GetTimeSignatureRef() {
			return ($this->m_timeSignature);
		}
		 
		 
		static function & GetTimeSignatureConstRef() {
			return ($this->m_timeSignature);
		}
		 
		 
		 
		// Rehearsal Sign Functions
		 
		function SetRehearsalSign(&$rehearsalSign) {
			$this->m_rehearsalSign = $rehearsalSign;
		}
		 
		 
		function GetRehearsalSign() {
			return ($this->m_rehearsalSign);
		}
		 
		 
		function & GetRehearsalSignRef() {
			return ($this->m_rehearsalSign);
		}
		 
		 
		static function & GetRehearsalSignConstRef() {
			return ($this->m_rehearsalSign);
		}
		 
		 
		 
		 
		 
		 
		function Barline($position=NULL, $type=NULL, $repeatCount=NULL) {
			 
			$this->m_keySignature = new KeySignature ();
			$this->m_timeSignature = new TimeSignature ();
			$this->m_rehearsalSign = new RehearsalSign ();
			
			$this->SetPosition($position);
			$this->SetType($type);
			$this->SetRepeatCount($repeatCount);
		}
		 
		
		// Serialize Functions
		 
		 
		 
		function DoSerialize(&$stream){
		 
			WRITE_BYTE ($stream,$this->m_position);
			WRITE_BYTE ($stream,$this->m_data);
		
		 
			$this->m_keySignature->DoSerialize($stream);

			$this->m_timeSignature->DoSerialize($stream);

			$this->m_rehearsalSign->DoSerialize($stream);


			return 1;
		}
		
		 
		 
		 
		 
		function DoDeserialize(&$stream){
		 
		
			$this->m_position = READ_BYTE ($stream);
			$this->m_data = READ_BYTE ($stream);
			
			$this->m_keySignature = new KeySignature ();
			$this->m_timeSignature = new TimeSignature ();
			$this->m_rehearsalSign = new RehearsalSign ();			
			
			$this->m_keySignature->DoDeserialize($stream);
		 
			$this->m_timeSignature->DoDeserialize($stream);
		 
			$this->m_rehearsalSign->DoDeserialize($stream);
		 
			return 1;
		}
		 
		// $this->Barline Data Functions
		
		 
		 
		 
		function SetBarlineData($type, $repeatCount) {
			 
			//------Last Checked------//
			// - Jan 4, 2005
			if (!$this->SetType($type))
				return 0;
			if (!$this->SetRepeatCount($repeatCount))
				return 0;
			return 1;
		}
		 
		 
		 
		 
		function GetBarlineData(&$type, &$repeatCount) {
			 
			//------Last Checked------//
			// - Jan 4, 2005
			$type = $this->GetType();
			$repeatCount = $this->GetRepeatCount();
		}
		 
		// Type Functions
		 
		 
		 
		function SetType($type) {
			 
			//------Last Checked------//
			// - Jan 4, 2005
			if (!$this->IsValidType($type)) return 0;
			 
			$this->m_data &= ~self::typeMask;
			$this->m_data |= ($type << 5);
			 
			return 1;
		}
		 
		// Repeat Count Functions
		 
		 
		 
		function SetRepeatCount($repeatCount) {
			 
			//------Last Checked------//
			// - Jan 4, 2005
			if (!$this->IsValidRepeatCount($repeatCount)) return 0;
			 
			$this->m_data &= ~self::repeatCountMask;
			$this->m_data |= $repeatCount;
			 
			return 1;
		}
		 
		 
	}
	 
?>

